package com.one.product.controller;

import com.one.Util;
import com.one.product.model.ShoppingCar;
import com.one.product.service.ProductService;

import javax.net.ssl.HandshakeCompletedEvent;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/getCar.do")
public class ShoppingCarInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取session对象并且拿session对象中的会员编号
        Object cId = req.getSession().getAttribute("customerId");
        if (cId == null) {
            //跳转到登录页面
            Util.writerData(resp,new ArrayList());
            return;
        }
        //将会员编号转换为字符串类型
        String customerId = cId.toString();
        ProductService productService = new ProductService();
        List<ShoppingCar> list = productService.getShoppingCarList(customerId);
        Util.writerData(resp,list);
    }
}
